Javascript setInterval and `this` solution

Posted by Michael on Stack Overflow See other posts from Stack Overflow or by Michael
Published on 2010-05-01T08:01:12Z Indexed on 2010/05/01 8:07 UTC
Read the original article Hit count: 212

Filed under:
|
|

I need to access this from my setInterval handler

prefs: null,
startup : function()
    {
        // init prefs
        ...
        this.retrieve_rate();
        this.intervalID = setInterval(this.retrieve_rate, this.INTERVAL);
    },

retrieve_rate : function()
    {
        var ajax = null;
        ajax = new XMLHttpRequest();
        ajax.open('GET', 'http://xyz.com', true);
        ajax.onload = function()
        {
            // access prefs here
        }
    }

How can I access this.prefs in ajax.onload ?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about this